package com.mega;

import static org.junit.Assert.*;

import java.util.concurrent.TimeUnit;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class Auto_sriman_webdriver01 {
public WebDriver driver;
//WebElement element;

//test


@Before
public void start()throws Exception {
	
System.out.println("dirver initilizing");
driver= new FirefoxDriver();
driver.get("http://insofthr.trial.orangehrmlive.com/");
//driver.manage().window().maximize(); 
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElement(By.id("txtUsername")).sendKeys("sravan");
driver.findElement(By.id("txtPassword")).sendKeys("selenium143");
driver.findElement(By.xpath("//*[@id='btnLogin']")).click();
assertEquals("Welcome sravan", driver.findElement(By.id("welcome")).getText());
 }

	@Test
    public void test(){
    System.out.println("Test");
    driver.findElement(By.id("menu_pim_viewMyDetails")).click();
    driver.findElement(By.linkText("Immigration")).click();
    driver.findElement(By.id("btnAdd")).click();
    driver.findElement(By.id("immigration_number")).clear();
    driver.findElement(By.id("immigration_number")).sendKeys("589457");
    driver.findElement(By.id("immigration_passport_issue_date")).clear();
    driver.findElement(By.id("immigration_passport_issue_date")).sendKeys("2009-01-23");
    driver.findElement(By.id("immigration_passport_expire_date")).clear();
    driver.findElement(By.id("immigration_passport_expire_date")).sendKeys("2019-04-14");
    driver.findElement(By.id("immigration_i9_status")).clear();
    driver.findElement(By.id("immigration_i9_status")).sendKeys("Active");
    /*for (int second = 0;; second++) {
    	if (second >= 60) fail("timeout");
    	try { if (isElementPresent(By.id("immigration_country"))) break; } catch (Exception e) {}
    	try {
			Thread.sleep(10000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }*/

    new Select(driver.findElement(By.id("immigration_country"))).selectByVisibleText("India");
    driver.findElement(By.id("immigration_i9_review_date")).clear();
    driver.findElement(By.id("immigration_i9_review_date")).sendKeys("2019-03-10");
    driver.findElement(By.id("immigration_comments")).clear();
    driver.findElement(By.id("immigration_comments")).sendKeys("Student Passport");
    driver.findElement(By.id("btnSave")).click();
}
	@Test
	public void test1() 
{
	
	    System.out.println("Test1");	
	    driver.findElement(By.id("menu_pim_viewMyDetails")).click();
	    driver.findElement(By.linkText("Immigration")).click();
	    driver.findElement(By.id("btnAddAttachment")).click();
       // driver.findElement(By.id("ufile")).clear();
	    driver.findElement(By.id("ufile")).sendKeys("C:\\Users\\Mittapally\\Pictures\\2012-04-24 001\\IMG_0202.JPG");
	    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
	    driver.findElement(By.id("btnSaveAttachment")).click();
	    driver.findElement(By.id("txtAttDesc")).clear();
	    driver.findElement(By.id("txtAttDesc")).sendKeys("My Date of Birth");
	    driver.findElement(By.id("btnSaveAttachment")).click();
        }
    
	
	@Test
	public void test2()
	{
            System.out.println("Test 2");
		    driver.findElement(By.id("menu_pim_viewMyDetails")).click();
		    assertEquals("Immigration", driver.findElement(By.linkText("Immigration")).getText());
		    driver.findElement(By.linkText("Immigration")).click();
		    driver.findElement(By.name("chkImmigration[]")).click();
		    driver.findElement(By.id("btnDelete")).click();
	
		
	
	} 



	

	@After
	public void afterTest(){
		System.out.println("its after test");
		driver.quit();
	}
}

